package demoMod.nanaki.cards.nanaki;

import com.badlogic.gdx.graphics.Color;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.animations.VFXAction;
import com.megacrit.cardcrawl.actions.common.DamageAllEnemiesAction;
import com.megacrit.cardcrawl.actions.common.MakeTempCardInDiscardAction;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.vfx.combat.VerticalAuraEffect;
import demoMod.nanaki.NanakiMod;

public class TurningLament extends AbstractNanakiCard {
    public static final String ID = NanakiMod.makeID("TurningLament");

    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG_PATH = "cards/TurningLament";

    private static final CardType TYPE = CardType.ATTACK;
    private static final CardRarity RARITY = CardRarity.UNCOMMON;
    private static final CardTarget TARGET = CardTarget.ALL_ENEMY;

    private static final int COST = 0;

    public TurningLament() {
        super(ID, NAME, NanakiMod.getResourcePath(IMG_PATH), COST, DESCRIPTION, TYPE, RARITY, TARGET);
        this.baseDamage = 4;
        this.baseMagicNumber = this.magicNumber = 1;
        this.isMultiDamage = true;
        this.exhaust = true;
    }

    @Override
    public Runnable getUpgradeAction() {
        return () -> upgradeMagicNumber(1);
    }

    @Override
    public void applyPowers() {
        this.baseDamage += AbstractDungeon.player.exhaustPile.size() * this.magicNumber;
        super.applyPowers();
        this.baseDamage -= AbstractDungeon.player.exhaustPile.size() * this.magicNumber;
    }

    @Override
    public void calculateCardDamage(AbstractMonster mo) {
        this.baseDamage += AbstractDungeon.player.exhaustPile.size() * this.magicNumber;
        super.calculateCardDamage(mo);
        this.baseDamage -= AbstractDungeon.player.exhaustPile.size() * this.magicNumber;
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        calculateCardDamage(null);
        addToBot(new DamageAllEnemiesAction(p, this.multiDamage, this.damageTypeForTurn, AbstractGameAction.AttackEffect.FIRE));
        addToBot(new VFXAction(p, new VerticalAuraEffect(Color.TEAL, p.hb.cX, p.hb.cY), 0.0F));
        for (AbstractMonster mo : AbstractDungeon.getCurrRoom().monsters.monsters) {
            if (!mo.isDeadOrEscaped()) {
                addToBot(new VFXAction(p, new VerticalAuraEffect(Color.TEAL, mo.hb.cX, mo.hb.cY), 0.0F));
            }
        }
        addToBot(new MakeTempCardInDiscardAction(this.makeStatEquivalentCopy(), 2));
    }
}
